# Based on the upstream weston aport
# Changes:
# - framebuffer no 0 hz patch for lg-mako, upstreamed here (this will be in the next weston release \o/):
#	https://patchwork.freedesktop.org/patch/150943/
# - APKBUILD arch changed to "all", upstreaming here:
#   https://github.com/alpinelinux/aports/pull/1689
pkgname=weston
pkgver=9999
_pkgver=3.0.0
pkgrel=6
_libname=lib$pkgname
_libdir=$_libname-${_pkgver%%.*}
pkgdesc="The reference Wayland server"
url="http://wayland.freedesktop.org"
arch="all"
license="MIT"
depends=""
makedepends="wayland-protocols libxkbcommon-dev xkeyboard-config libinput-dev libunwind-dev mtdev-dev libxcursor-dev glu-dev pango-dev colord-dev freerdp-dev libwebp-dev libva-dev dbus-dev linux-pam-dev"
_cms="cms-colord cms-static"
_shell="shell-desktop shell-fullscreen shell-ivi"
_client="info terminal wcap-decode"
_backend="backend-drm backend-fbdev backend-headless
	backend-rdp backend-x11 backend-wayland
	"
options="!check"

for _sub in $_cms $_shell $_client $_backend; do
	subpackages="$subpackages $pkgname-$_sub:_sub"
done
subpackages="$pkgname-dev $pkgname-doc $subpackages
	$pkgname-clients $_libname-desktop:_libd $_libname:libs
	$pkgname-xwayland $pkgname-desktop-x11:_x11:noarch
"
source="
	http://wayland.freedesktop.org/releases/$pkgname-$_pkgver.tar.xz
	0001-compositor-fbdev-Added-parameter-pixman-type.patch
	0002-compositor-fbdev-Add-support-for-ABGR.patch
	0003-compositor-fbdev-print-the-pixman-type-guessed-in-ca.patch
	0004-musl-weston-launcher.patch
	0005-timespec.patch
	0006-compositor-fbdev-fix-start-up-assertion.patch
"
builddir="$srcdir/$pkgname-$_pkgver"

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--libexecdir=/usr/lib/$pkgname \
		--enable-rdp-compositor \
		--enable-screen-sharing \
		--enable-vaapi-recorder \
		--enable-clients \
		--enable-demo-clients-install \
		--disable-setuid-install
	make
}

check() {
	make -C "$builddir" check
	return 0
}

package() {
	make  -C "$builddir" DESTDIR="$pkgdir" install
}

libs() {
	depends="xkeyboard-config"
	default_libs
}

_libd() {
	pkgdesc="Desktop shells abstraction library for libweston compositors"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*desktop* "$subpkgdir"/usr/lib
}

clients() {
	pkgdesc="Weston example clients"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/$pkgname-* "$subpkgdir"/usr/bin
}

xwayland() {
	pkgdesc="Wayland module to run X Clients"
	mkdir -p "$subpkgdir"/usr/lib/$_libdir
	mv "$pkgdir"/usr/lib/$_libdir/xwayland.so \
		"$subpkgdir"/usr/lib/$_libdir
}

_x11() {
	pkgdesc="Weston desktop helper pack (x11 backend)"
	depends="$pkgname $pkgname-shell-desktop $pkgname-xwayland
		$pkgname-backend-x11 $pkgname-terminal"
	mkdir -p "$subpkgdir"
}

_sub() {
	local name path
	case $subpkgname in
	*-cms-*)
		name=${subpkgname#$pkgname-cms-}
		path=/usr/lib/$pkgname
		pkgdesc="Weston CMS module: $name"
		name=cms-$name.so
		;;
	*-shell-*)
		name=${subpkgname#$pkgname-shell-}
		path=/usr/lib/$pkgname
		pkgdesc="Weston shell: $name"
		name=*$name-shell*
		;;
	*-backend-*)
		name=${subpkgname#$pkgname-backend-}
		path=/usr/lib/$_libdir
		pkgdesc="Weston backend: $name"
		name=$name-backend.so
		grep -q cairo "$pkgdir"/$path/$name && depends="mesa-dri-swrast"
		;;
	*)
		name=$subpkgname
		path=/usr/bin
		[ -x "$pkgdir"/$path/$name ] || name=${subpkgname#$pkgname-}
		pkgdesc="Weston client: $name"
		;;
	esac
	mkdir -p "$subpkgdir"/$path
	mv "$pkgdir"/$path/$name "$subpkgdir"/$path
}
sha512sums="b824c39f2a884f6d50d607613f447090621f684c96f7d905f25f6e500dabd03ecb2b1cd1030babc193c3417223cb220103abb792437e1a5ead7229a76b5c7a58  weston-3.0.0.tar.xz
2daa68ee19f4e123d7f3148517c2afcd4df0f065815a0e28db38f301260cd833b7170060c46127e65a25021e2d814afb40fc0f2987cbb3ab5cd4f9dae778bc98  0001-compositor-fbdev-Added-parameter-pixman-type.patch
fa1099258aaef38f228de2e9ca3e2ae5e9e21ed10891f8686f5abd16d7f6bc6c57e43e0bfc3175ed70f32bb80d98f6ec009e663cd4f8724e29dea13c7fcc12fb  0002-compositor-fbdev-Add-support-for-ABGR.patch
b5eb741ea8b6fcbd9de95e773fe0bf4ae6588ef57564f97a65aefc6c7ec29f1a01de9764a25672fd7c76c8ff514b497743cbaf279818123041c161c7a1e62bb6  0003-compositor-fbdev-print-the-pixman-type-guessed-in-ca.patch
856a28a324cb9adf94b92bf5489ff43827d57e6acee0c7e0e558018357166b782126e086a4308c3e3499d068fa07f02862cc20cdfbc9a3d6af30ec823eb1b78f  0004-musl-weston-launcher.patch
3e596af4bf0a6b06a5d28376043db111fe1c161ead04501fa6d2c667b5a21889cca3354d1bdc4ac794841bef68ed5e1a7a84e44e7d510e947e3673195706caed  0005-timespec.patch
5d356bc8534c5486b0c5daf727fb8d2cd8409f7f964e3f391c225a2b21b9f293e36d10344f55f0e6566bfbde415c990a72d57fe5db6081acd3c788106cda319f  0006-compositor-fbdev-fix-start-up-assertion.patch"
